package com.example.bookrecommendationjava.mapper;

import com.example.bookrecommendationjava.model.Book;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @BelongsProject: book-recommendation-java
 * @BelongsPackage: com.example.bookrecommendationjava.mapper
 * @Author: ZhShy
 * @CreateTime: 2022-03-14 20:31
 * @Description:
 */
@Mapper
public interface BookMapper {
    @Insert("insert into book (bookUrl, bookImgUrl, bookName, bookAuthor) " +
            "values ('${bookUrl}', '${bookImgUrl}', '${bookName}', '${bookAuthor}')")
    void insertIntoBook(Book book);

    @Select("select * from book")
    List<Book> selectAllFromBook();

    @Select("select * from book where bookId not in (select bookId from likelist where userId=${userId})")
    List<Book> selectAllFromBookByBookIdNotInLikeByUserId(Integer userId);

    @Select("select * from book where bookId in (select bookId from likelist where userId=${userId}) order by bookId desc")
    List<Book> selectAllFromBookByBookIdInLikeByUserId(Integer userId);

    @Select("select max(bookId) from book")
    Integer selectMaxBookIdFromBook();

    @Select("select * from book where bookId in (${recommend})")
    List<Book> selectFromBookByBookIdInRecommend(String recommend);
}
